/**  
* @Title: BannerController.java
* @Package com.lemon.controller.cityRun
* @Description: (一句话阐述):
* @author Ran_cc
* @date 2018年10月22日
* @version V1.0  
*/
package com.lemon.controller.cityRun;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.lemon.conf.MyException;
import com.lemon.conf.MyInterceptor.LoginRequired;
import com.lemon.model.cityRun.CrAdBanner;
import com.lemon.service.cityRun.CrAdBannerService;
import com.lemon.utils.ReqResult;

/**
 * <p>Title: BannerController</p>
 * <p>Description: 
 * </p>
 * <p>Company: </p>
 * @author Ran_cc
 * @date 2018年10月22日
 * @版本 V 1.0 
 */
@RestController
@RequestMapping("/ad")
public class BannerController {
	@Resource
	private CrAdBannerService adService;

	//获取全部用户信息
	@RequestMapping("/getBannerList")
	public ReqResult getShopsList(@ModelAttribute CrAdBanner ad , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();

		try {
			ad.setWhere(" and status != 0 ");
			ad.setOrderBy(" order By sort asc ");
			List<CrAdBanner> selectListBySelective = adService.selectListBySelective(ad);

			reqResult.setReturnResult(selectListBySelective);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}
	@RequestMapping("/getBannerById")
	public ReqResult getBannerById(@ModelAttribute CrAdBanner ad , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			List<CrAdBanner> selectListBySelective = adService.selectListBySelective(ad);
			reqResult.setReturnResult(selectListBySelective.size() > 0 ? selectListBySelective.get(0) : null);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}


	/**
	 * <b>Description:<blockquote> 新增广告管理
	 * </blockquote></b>
	 * 
	 * @Title: addShopInfo
	 * @param ad
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月22日
	 */
	@LoginRequired
	@RequestMapping(value = "/addBannerInfo.do" , method = RequestMethod.POST)
	public ReqResult addShopInfo(@ModelAttribute CrAdBanner ad , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			int row = adService.insertBySelective(ad);

			reqResult.setReturnResult("");
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote> 修改广告信息
	 * </blockquote></b>
	 * 
	 * @Title: updateBannerInfo
	 * @param ad
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月22日
	 */
	@LoginRequired
	@RequestMapping(value = "/updateBannerInfo.do" , method = RequestMethod.POST)
	public ReqResult updateBannerInfo(@ModelAttribute CrAdBanner ad , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			int row = adService.updateBannerInfo(ad);
			reqResult.setReturnResult(row);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

}
